package examples;

import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class UICatalog extends MIDlet implements CommandListener {

	private Display display;
	
	public UICatalog() {
		// TODO Auto-generated constructor stub
		super();
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		// TODO Auto-generated method stub

	}

	protected void pauseApp() {
		// TODO Auto-generated method stub

	}

	protected void startApp() throws MIDletStateChangeException {
		// TODO Auto-generated method stub
		display = Display.getDisplay(this);
		
		Image img = null;
		try {
			img = Image.createImage("/images/taichi.png");
		}catch (Exception e) {
			System.out.println(e);
		}
		
		List list1 = new List("List Test", Choice.EXCLUSIVE);
		list1.append("Alibaba", img);
		list1.append("Tencent", null);
		list1.append("Baidu", null);
		list1.setSelectedIndex(0, true);
		list1.addCommand(new Command("OK", Command.OK, 1));
		list1.setCommandListener(this);
		display.setCurrent(list1);
	}

	public void commandAction(Command c, Displayable s) {
		// TODO Auto-generated method stub
		if (c == List.SELECT_COMMAND) {
			List list = (List)s;
			System.out.println("You selecting the "+list.getSelectedIndex()+"th:"+list.getString(list.getSelectedIndex()));
		}
		else {
			String cmd = c.getLabel();
			if (cmd.equals("OK")) {
				List list = (List)s;
				System.out.println("You verified the "+list.getSelectedIndex()+"th:"+list.getString(list.getSelectedIndex()));
			}
		}
	}

}
